package com.carleasoft.mps.cms.business.process.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.carleasoft.mps.cms.business.drug.bean.entity.DrugOilManage;
import com.carleasoft.mps.cms.business.leave.bean.entity.LeaveReportUserEntity;
import com.carleasoft.mps.cms.business.leave.service.LeaveReportUserService;
import com.carleasoft.mps.cms.business.process.bean.entity.*;
import com.carleasoft.mps.cms.business.process.bean.po.*;
import com.carleasoft.mps.cms.business.process.bean.vo.GetProcessInfoVo;
import com.carleasoft.mps.cms.business.process.bean.vo.MyApprovalPageReportVo;
import com.carleasoft.mps.cms.business.process.bean.vo.MyApprovalPageVo;
import com.carleasoft.mps.cms.business.process.bean.vo.UserInfoVos;
import com.carleasoft.mps.cms.business.process.dao.BaseProcessNodeRelMapper;
import com.carleasoft.mps.cms.business.process.service.*;
import com.carleasoft.mps.cms.business.train.bean.vo.TrainCarVo;
import com.carleasoft.mps.core.user.ThreadUserContext;
import com.carleasoft.mps.core.user.UserCacheData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author: yangHao
 * @createDate:2023/6/2
 * @description:
 */
@Service
public class BaseProcessNodeRelServiceImpl extends ServiceImpl<BaseProcessNodeRelMapper, BaseProcessNodeRelEntity> implements BaseProcessNodeRelService {

    @Autowired
    private BaseProcessModuleService baseProcessModuleService;
    @Autowired
    private BaseProcessNodeAssigneeService baseProcessNodeAssigneeService;
    @Autowired
    private ProcessApprovalService processApprovalService;
    @Autowired
    private BusinessNodeService businessNodeService;
    @Autowired
    private LeaveReportUserService leaveReportUserService;


    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveNode(NodePo nodePo) {
        boolean isOk = false;
        UserCacheData user = ThreadUserContext.getCurrentCacheUser();
        if (StrUtil.isNotBlank(nodePo.getModuleCode())) {
            BaseProcessModuleEntity baseProcessModuleServiceOne = baseProcessModuleService.getOne(Wrappers.<BaseProcessModuleEntity>lambdaQuery()
                    .eq(BaseProcessModuleEntity::getModuleCode, nodePo.getModuleCode()));
            baseProcessModuleServiceOne.setRemark(nodePo.getRemark());
            baseProcessModuleServiceOne.setUpdateTime(LocalDateTime.now());
            baseProcessModuleServiceOne.setUpdatePersonCode(user.getUserCode());
            baseProcessModuleServiceOne.setUpdatePersonName(user.getUserName());
            baseProcessModuleServiceOne.setModuleName(nodePo.getModuleName());
            isOk = baseProcessModuleService.updateById(baseProcessModuleServiceOne);
            isOk = this.remove(Wrappers.<BaseProcessNodeRelEntity>lambdaQuery()
                    .eq(BaseProcessNodeRelEntity::getModuleCode, nodePo.getModuleCode()));
            isOk = baseProcessNodeAssigneeService.remove(Wrappers.<BaseProcessNodeAssigneeEntity>lambdaQuery()
                    .eq(BaseProcessNodeAssigneeEntity::getModuleCode, nodePo.getModuleCode()));
        } else {
            BaseProcessModuleEntity baseProcessModuleEntity = new BaseProcessModuleEntity();
            String idStr = IdWorker.getIdStr();
            nodePo.setModuleCode(idStr);
            baseProcessModuleEntity.setModuleCode(idStr);
            baseProcessModuleEntity.setCreatePersonCode(user.getUserCode());
            baseProcessModuleEntity.setCreatePersonName(user.getUserName());
            baseProcessModuleEntity.setCreateTime(LocalDateTime.now());
            baseProcessModuleEntity.setUpdatePersonCode(user.getUserCode());
            baseProcessModuleEntity.setUpdatePersonName(user.getUserName());
            baseProcessModuleEntity.setUpdateTime(LocalDateTime.now());
            baseProcessModuleEntity.setType(nodePo.getType());
            baseProcessModuleEntity.setModuleName(nodePo.getModuleName());
            baseProcessModuleEntity.setRemark(nodePo.getRemark());
            isOk = baseProcessModuleService.save(baseProcessModuleEntity);
        }
        isOk = this.nodeInfo(nodePo.getBaseNodePos(), nodePo.getModuleCode());

        return isOk;
    }

    @Override
    public Page<BaseProcessModuleEntity> pageQuery(Page page, NodePo nodePo) {
        QueryWrapper<BaseProcessModuleEntity> queryWrapper = new QueryWrapper<>();
        if (nodePo.getType() != null) {
            queryWrapper.eq("TYPE", nodePo.getType());

        }
        queryWrapper.orderByDesc("UPDATE_TIME");
        return baseProcessModuleService.page(page, queryWrapper);
    }

    @Override
    public NodePo detail(NodePo nodePo) {
        NodePo po = new NodePo();
        BaseProcessModuleEntity baseProcessModuleServiceOne = baseProcessModuleService.getOne(Wrappers.<BaseProcessModuleEntity>lambdaQuery()
                .eq(BaseProcessModuleEntity::getModuleCode, nodePo.getModuleCode()));
        po.setModuleCode(baseProcessModuleServiceOne.getModuleCode());
        po.setType(baseProcessModuleServiceOne.getType());
        po.setRemark(baseProcessModuleServiceOne.getRemark());
        po.setModuleName(baseProcessModuleServiceOne.getModuleName());
        List<BaseNodePo> baseNodePos = new ArrayList<>();
        List<BaseProcessNodeRelEntity> processNodeRelEntities = this.list(Wrappers.<BaseProcessNodeRelEntity>lambdaQuery()
                .eq(BaseProcessNodeRelEntity::getModuleCode, nodePo.getModuleCode()));
        List<String> nodeCodes = processNodeRelEntities.stream().map(BaseProcessNodeRelEntity::getNodeCode).collect(Collectors.toList());
        List<BaseProcessNodeAssigneeEntity> nodeAssigneeEntities = baseProcessNodeAssigneeService.list(Wrappers.<BaseProcessNodeAssigneeEntity>lambdaQuery()
                .in(BaseProcessNodeAssigneeEntity::getNodeCode, nodeCodes)
                .eq(BaseProcessNodeAssigneeEntity::getModuleCode, nodePo.getModuleCode()));
        Map<String, BaseProcessNodeAssigneeEntity> map = nodeAssigneeEntities.stream().collect(Collectors.toMap(BaseProcessNodeAssigneeEntity::getNodeCode, Function.identity()));
        for (BaseProcessNodeRelEntity processNodeRelEntity : processNodeRelEntities) {
            BaseNodePo baseNodePo = new BaseNodePo();
            baseNodePo.setNodeName(processNodeRelEntity.getNodeName());
            baseNodePo.setNodeCode(processNodeRelEntity.getNodeCode());
            baseNodePo.setApprovalPersonTypeModel(processNodeRelEntity.getApprovalPersonTypeModel());
            if (map.containsKey(processNodeRelEntity.getNodeCode())) {
                baseNodePo.setCode(map.get(processNodeRelEntity.getNodeCode()).getUserCode());
                baseNodePo.setName(map.get(processNodeRelEntity.getNodeCode()).getUserName());
            }
            baseNodePos.add(baseNodePo);
        }
        po.setBaseNodePos(baseNodePos);
        return po;
    }

    @Override
    public NodePo getModuleInfo(NodePo nodePo) {
        NodePo po = new NodePo();
        BaseProcessModuleEntity baseProcessModuleServiceOne = baseProcessModuleService.getOne(Wrappers.<BaseProcessModuleEntity>lambdaQuery()
                .eq(BaseProcessModuleEntity::getType, nodePo.getType()));
        po.setModuleCode(baseProcessModuleServiceOne.getModuleCode());
        po.setType(baseProcessModuleServiceOne.getType());
        po.setRemark(baseProcessModuleServiceOne.getRemark());
        po.setModuleName(baseProcessModuleServiceOne.getModuleName());
        List<BaseNodePo> baseNodePos = new ArrayList<>();
        List<BaseProcessNodeRelEntity> processNodeRelEntities = this.list(Wrappers.<BaseProcessNodeRelEntity>lambdaQuery()
                .eq(BaseProcessNodeRelEntity::getModuleCode, baseProcessModuleServiceOne.getModuleCode()));
        List<String> nodeCodes = processNodeRelEntities.stream().map(BaseProcessNodeRelEntity::getNodeCode).collect(Collectors.toList());
        List<BaseProcessNodeAssigneeEntity> nodeAssigneeEntities = baseProcessNodeAssigneeService.list(Wrappers.<BaseProcessNodeAssigneeEntity>lambdaQuery()
                .in(BaseProcessNodeAssigneeEntity::getNodeCode, nodeCodes)
                .eq(BaseProcessNodeAssigneeEntity::getModuleCode, baseProcessModuleServiceOne.getModuleCode()));
        Map<String, BaseProcessNodeAssigneeEntity> map = nodeAssigneeEntities.stream().collect(Collectors.toMap(BaseProcessNodeAssigneeEntity::getNodeCode, Function.identity()));
        for (BaseProcessNodeRelEntity processNodeRelEntity : processNodeRelEntities) {
            BaseNodePo baseNodePo = new BaseNodePo();
            baseNodePo.setNodeName(processNodeRelEntity.getNodeName());
            baseNodePo.setNodeCode(processNodeRelEntity.getNodeCode());
            baseNodePo.setApprovalPersonTypeModel(processNodeRelEntity.getApprovalPersonTypeModel());
            if (map.containsKey(processNodeRelEntity.getNodeCode()) && processNodeRelEntity.getApprovalPersonTypeModel().equals(2)) {
                baseNodePo.setCode(map.get(processNodeRelEntity.getNodeCode()).getUserCode());
                baseNodePo.setName(map.get(processNodeRelEntity.getNodeCode()).getUserName());
            }
            if (processNodeRelEntity.getApprovalPersonTypeModel().equals(1) && map.containsKey(processNodeRelEntity.getNodeCode())) {
                String deptCode = map.get(processNodeRelEntity.getNodeCode()).getUserCode();
                BaseNodePo info = this.getBaseMapper().getUserInfo(deptCode);
                baseNodePo.setName(info.getName());
                baseNodePo.setCode(info.getCode());
            }
            baseNodePos.add(baseNodePo);
        }
        po.setBaseNodePos(baseNodePos);
        return po;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean submitApproval(NodePo nodePo) {
        boolean isOk = false;
        UserCacheData user = ThreadUserContext.getCurrentCacheUser();
        ProcessApprovalEntity processApprovalEntity = new ProcessApprovalEntity();
        processApprovalEntity.setBusinessCode(nodePo.getBisCode());
        processApprovalEntity.setId(IdWorker.getIdStr());
        processApprovalEntity.setCreateTime(LocalDateTime.now());
        if (Objects.nonNull(user) && user.getUserCode()!=null){
            processApprovalEntity.setCreatePersonCode(user.getUserCode());
            processApprovalEntity.setCreatePersonName(user.getUserName());
        }

        processApprovalEntity.setProcessCode(IdWorker.getIdStr());
        processApprovalEntity.setStatus(1);
        processApprovalEntity.setType(nodePo.getType());
        String idStr = IdWorker.getIdStr();
        processApprovalEntity.setProcessCode(idStr);
        isOk = processApprovalService.save(processApprovalEntity);
        List<BusinessNodeEntity> businessNodeEntities = new ArrayList<>();
        for (int i = 0; i < nodePo.getBaseNodePos().size(); i++) {
            BaseNodePo baseNodePo = nodePo.getBaseNodePos().get(i);
            BusinessNodeEntity businessNodeEntity = new BusinessNodeEntity();
            businessNodeEntity.setId(IdWorker.getIdStr());
            businessNodeEntity.setCode(baseNodePo.getCode());
            businessNodeEntity.setName(baseNodePo.getName());
            businessNodeEntity.setNodeName(baseNodePo.getNodeName());
            businessNodeEntity.setNodeCode(baseNodePo.getNodeCode());
            businessNodeEntity.setProcessCode(idStr);
            businessNodeEntity.setSequence(i + 1);
            if (i == 0) {
                businessNodeEntity.setApprovalResult(1);
            } else {
                businessNodeEntity.setApprovalResult(0);
            }
            businessNodeEntities.add(businessNodeEntity);
        }
        isOk = businessNodeService.saveBatch(businessNodeEntities);
        return isOk;
    }

    @Override
    public Page<MyApprovalPageVo> myApprovalPage(Page page, MyApprovalPagePo myApprovalPagePo) {
        UserCacheData user = ThreadUserContext.getCurrentCacheUser();
        myApprovalPagePo.setUserCode(user.getUserCode());
        Page<MyApprovalPageVo> myApprovalPageVoPage = this.getBaseMapper().myApprovalPage(page, myApprovalPagePo);
        if (CollUtil.isNotEmpty(myApprovalPageVoPage.getRecords())) {
            List<String> leaveCode = myApprovalPageVoPage.getRecords().stream().map(MyApprovalPageVo::getLeaveCode).collect(Collectors.toList());
            List<LeaveReportUserEntity> leaveReportUserEntities = leaveReportUserService.list(Wrappers.<LeaveReportUserEntity>lambdaQuery()
                    .in(LeaveReportUserEntity::getLeaveReportCode, leaveCode));
            Map<String, List<LeaveReportUserEntity>> map = leaveReportUserEntities.stream().collect(Collectors.groupingBy(LeaveReportUserEntity::getLeaveReportCode));
            Set<String> userCodes = leaveReportUserEntities.stream().map(LeaveReportUserEntity::getUserCode).collect(Collectors.toSet());
            List<UserInfoVos> userInfoVos = this.getBaseMapper().userCodes(userCodes);
            Map<String, List<UserInfoVos>> listMap = new HashMap<>();
            if (CollUtil.isNotEmpty(userInfoVos)) {
                listMap = userInfoVos.stream().collect(Collectors.groupingBy(UserInfoVos::getUserCode));
            }
            for (MyApprovalPageVo record : myApprovalPageVoPage.getRecords()) {
                List<LeaveReportUserEntity> reportUserEntities = map.get(record.getLeaveCode());
                StringBuilder userName = new StringBuilder();
                for (int i = 0; i < reportUserEntities.size(); i++) {
                    LeaveReportUserEntity leaveReportUserEntity = reportUserEntities.get(i);
                    StringBuilder deptName = new StringBuilder();
                    if (listMap.containsKey(leaveReportUserEntity.getUserCode())) {
                        List<UserInfoVos> infoVos = listMap.get(leaveReportUserEntity.getUserCode());
                        for (int i1 = 0; i1 < infoVos.size(); i1++) {
                            UserInfoVos infoVos1 = infoVos.get(i1);
                            if (i1 == infoVos.size() - 1) {
                                deptName.append(infoVos1.getDeptName());
                            } else {
                                deptName.append(infoVos1.getDeptName()).append("、");
                            }

                        }
                    }

                    if (i == reportUserEntities.size() - 1) {
                        if (StrUtil.isNotBlank(deptName)) {
                            userName.append(leaveReportUserEntity.getUserName()).append("(").append(deptName).append(")");
                        } else {
                            userName.append(leaveReportUserEntity.getUserName());
                        }
                    } else {
                        if (StrUtil.isNotBlank(deptName)) {
                            userName.append(leaveReportUserEntity.getUserName()).append("(").append(deptName).append(")").append("、");
                        } else {
                            userName.append(leaveReportUserEntity.getUserName()).append("、");


                        }
                    }
                }

                record.setUserName(userName.toString());
            }
        }

        return myApprovalPageVoPage;
    }

    @Override
    public Page<MyApprovalPageReportVo> myApprovalPageReport(Page page, MyApprovalPagePo myApprovalPagePo) {
        UserCacheData user = ThreadUserContext.getCurrentCacheUser();
        myApprovalPagePo.setUserCode(user.getUserCode());
        Page<MyApprovalPageReportVo> myApprovalPageReportVoPage = this.getBaseMapper().myApprovalPageReport(page, myApprovalPagePo);

        if (CollUtil.isNotEmpty(myApprovalPageReportVoPage.getRecords())) {
            List<String> leaveCode = myApprovalPageReportVoPage.getRecords().stream().map(MyApprovalPageReportVo::getReportCode).collect(Collectors.toList());
            List<LeaveReportUserEntity> leaveReportUserEntities = leaveReportUserService.list(Wrappers.<LeaveReportUserEntity>lambdaQuery()
                    .in(LeaveReportUserEntity::getLeaveReportCode, leaveCode));
            Map<String, List<LeaveReportUserEntity>> map = leaveReportUserEntities.stream().collect(Collectors.groupingBy(LeaveReportUserEntity::getLeaveReportCode));
            Set<String> userCodes = leaveReportUserEntities.stream().map(LeaveReportUserEntity::getUserCode).collect(Collectors.toSet());
            List<UserInfoVos> userInfoVos = this.getBaseMapper().userCodes(userCodes);
            Map<String, List<UserInfoVos>> listMap = new HashMap<>();
            if (CollUtil.isNotEmpty(userInfoVos)) {
                listMap = userInfoVos.stream().collect(Collectors.groupingBy(UserInfoVos::getUserCode));
            }
            for (MyApprovalPageReportVo record : myApprovalPageReportVoPage.getRecords()) {
                List<LeaveReportUserEntity> reportUserEntities = map.get(record.getReportCode());
                StringBuilder userName = new StringBuilder();
                for (int i = 0; i < reportUserEntities.size(); i++) {
                    LeaveReportUserEntity leaveReportUserEntity = reportUserEntities.get(i);
                    StringBuilder deptName = new StringBuilder();
                    if (listMap.containsKey(leaveReportUserEntity.getUserCode())) {
                        List<UserInfoVos> infoVos = listMap.get(leaveReportUserEntity.getUserCode());
                        for (int i1 = 0; i1 < infoVos.size(); i1++) {
                            UserInfoVos infoVos1 = infoVos.get(i1);
                            if (i1 == infoVos.size() - 1) {
                                deptName.append(infoVos1.getDeptName());
                            } else {
                                deptName.append(infoVos1.getDeptName()).append("、");
                            }

                        }
                    }

                    if (i == reportUserEntities.size() - 1) {
                        if (StrUtil.isNotBlank(deptName)) {
                            userName.append(leaveReportUserEntity.getUserName()).append("(").append(deptName).append(")");
                        } else {
                            userName.append(leaveReportUserEntity.getUserName());
                        }
                    } else {
                        if (StrUtil.isNotBlank(deptName)) {
                            userName.append(leaveReportUserEntity.getUserName()).append("(").append(deptName).append(")").append("、");
                        } else {
                            userName.append(leaveReportUserEntity.getUserName()).append("、");
                        }
                    }
                }
                record.setUserName(userName.toString());
            }
        }

        return myApprovalPageReportVoPage;
    }

    @Override
    public Page<TrainCarVo> myApprovalPageCar(Page page, MyApprovalPageCarPo myApprovalPageCarPo) {
        if (myApprovalPageCarPo.getResourceType()!=null){
            UserCacheData user = ThreadUserContext.getCurrentCacheUser();
            myApprovalPageCarPo.setUserCode(user.getUserCode());
        }
        return this.getBaseMapper().myApprovalPageCar(page, myApprovalPageCarPo);

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer check(CheckPo checkPo) {
        // isNotPass 是否需要调用接口修改业务主表状态   1代表需要调用  0代表不需要
        int isNotPass = 0;
        boolean isOk = false;
        BusinessNodeEntity businessNodeServiceById = businessNodeService.getById(checkPo.getId());
        isOk = businessNodeService.update(Wrappers.<BusinessNodeEntity>lambdaUpdate()
                .eq(BusinessNodeEntity::getId, businessNodeServiceById.getId())
                .set(BusinessNodeEntity::getApprovalOpinion, checkPo.getApprovalOpinion())
                .set(BusinessNodeEntity::getApprovalResult, checkPo.getStatus())
                .set(BusinessNodeEntity::getOperationTime, new Date()));
        if (checkPo.getStatus() == 2) {
            BusinessNodeEntity businessNodeServiceOne = businessNodeService.getOne(Wrappers.<BusinessNodeEntity>lambdaQuery()
                    .eq(BusinessNodeEntity::getProcessCode, businessNodeServiceById.getProcessCode())
                    .eq(BusinessNodeEntity::getSequence, businessNodeServiceById.getSequence() + 1)
                    .eq(BusinessNodeEntity::getApprovalResult, 0));
            if (Objects.nonNull(businessNodeServiceOne)) {
                businessNodeServiceOne.setApprovalResult(1);
                isOk = businessNodeService.update(Wrappers.<BusinessNodeEntity>lambdaUpdate()
                        .eq(BusinessNodeEntity::getId, businessNodeServiceOne.getId())
                        .set(BusinessNodeEntity::getApprovalResult, 1));
            } else {
                ProcessApprovalEntity processApprovalServiceOne = processApprovalService.getOne(Wrappers.<ProcessApprovalEntity>lambdaQuery()
                        .eq(ProcessApprovalEntity::getProcessCode, businessNodeServiceById.getProcessCode()));
                processApprovalServiceOne.setStatus(checkPo.getStatus());
                isOk = processApprovalService.update(Wrappers.<ProcessApprovalEntity>lambdaUpdate()
                        .eq(ProcessApprovalEntity::getId, processApprovalServiceOne.getId())
                        .set(ProcessApprovalEntity::getStatus, checkPo.getStatus()));
                isNotPass = 1;
            }
        } else {
            List<BusinessNodeEntity> businessNodeEntities = businessNodeService.list(Wrappers.<BusinessNodeEntity>lambdaQuery()
                    .eq(BusinessNodeEntity::getProcessCode, businessNodeServiceById.getProcessCode())
                    .gt(BusinessNodeEntity::getSequence, businessNodeServiceById.getSequence()));
            if (CollUtil.isNotEmpty(businessNodeEntities)) {
                List<String> ids = businessNodeEntities.stream().map(BusinessNodeEntity::getId).collect(Collectors.toList());
                isOk = businessNodeService.removeByIds(ids);
            }
            ProcessApprovalEntity processApprovalServiceOne = processApprovalService.getOne(Wrappers.<ProcessApprovalEntity>lambdaQuery()
                    .eq(ProcessApprovalEntity::getProcessCode, businessNodeServiceById.getProcessCode()));
            processApprovalServiceOne.setStatus(checkPo.getStatus());
            isOk = processApprovalService.update(Wrappers.<ProcessApprovalEntity>lambdaUpdate()
                    .eq(ProcessApprovalEntity::getProcessCode, businessNodeServiceById.getProcessCode())
                    .set(ProcessApprovalEntity::getStatus, checkPo.getStatus()));
            isNotPass = 1;
        }
        return isNotPass;
    }

    @Override
    public GetProcessInfoVo getProcessInfo(GetProcessInfoPo getProcessInfoPo) {
        ProcessApprovalEntity processApprovalServiceOne = processApprovalService.getOne(Wrappers.<ProcessApprovalEntity>lambdaQuery()
                .eq(ProcessApprovalEntity::getBusinessCode, getProcessInfoPo.getBisCode()));
        GetProcessInfoVo getProcessInfoVo = new GetProcessInfoVo();
        getProcessInfoVo.setCreateTime(processApprovalServiceOne.getCreateTime());
        getProcessInfoVo.setCreatePersonName(processApprovalServiceOne.getCreatePersonName());
        List<BusinessNodeEntity> nodeEntities = businessNodeService.list(Wrappers.<BusinessNodeEntity>lambdaQuery()
                .eq(BusinessNodeEntity::getProcessCode, processApprovalServiceOne.getProcessCode()));
        getProcessInfoVo.setBusinessNodeEntities(nodeEntities);
        return getProcessInfoVo;
    }


    private boolean nodeInfo(List<BaseNodePo> baseNodePos, String moduleCode) {
        boolean isOk = false;
        List<BaseProcessNodeRelEntity> baseProcessNodeRelEntities = new ArrayList<>();
        List<BaseProcessNodeAssigneeEntity> baseProcessNodeAssigneeEntities = new ArrayList<>();
        for (int i = 0; i < baseNodePos.size(); i++) {
            String str = IdWorker.getIdStr();
            BaseNodePo baseNodePo = baseNodePos.get(i);
            BaseProcessNodeRelEntity baseProcessNodeRelEntity = new BaseProcessNodeRelEntity();
            baseProcessNodeRelEntity.setNodeCode(str);
            baseProcessNodeRelEntity.setNodeName(baseNodePo.getNodeName());
            baseProcessNodeRelEntity.setSequence(i + 1);
            baseProcessNodeRelEntity.setApprovalPersonTypeModel(baseNodePo.getApprovalPersonTypeModel());
            baseProcessNodeRelEntity.setModuleCode(moduleCode);
            baseProcessNodeRelEntities.add(baseProcessNodeRelEntity);
            BaseProcessNodeAssigneeEntity baseProcessNodeAssigneeEntity = new BaseProcessNodeAssigneeEntity();
            baseProcessNodeAssigneeEntity.setNodeCode(str);
            baseProcessNodeAssigneeEntity.setModuleCode(moduleCode);
            baseProcessNodeAssigneeEntity.setUserCode(baseNodePo.getCode());
            if (baseNodePo.getApprovalPersonTypeModel().equals(1)) {
                String deptName = this.getBaseMapper().getDeptInfo(baseNodePo.getCode());
                baseProcessNodeAssigneeEntity.setUserName(deptName);
            } else if (baseNodePo.getApprovalPersonTypeModel().equals(2)) {
                String name = this.getBaseMapper().userInfo(baseNodePo.getCode());
                baseProcessNodeAssigneeEntity.setUserName(name);
            }
            baseProcessNodeAssigneeEntities.add(baseProcessNodeAssigneeEntity);
        }
        isOk = this.saveBatch(baseProcessNodeRelEntities);
        isOk = baseProcessNodeAssigneeService.saveBatch(baseProcessNodeAssigneeEntities);
        return isOk;
    }
}
